﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HigLabo.CodeGenerator;
using System.IO;

namespace HigLabo.CodeGenerator.Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            var sourceCode = new SourceCode();
            
            var ns = new Namespace("HigLabo.CodeGenerator.Sample");
            sourceCode.Namespaces.Add(ns);

            var c = new Class(AccessModifier.Public, "Person");
            ns.Classes.Add(c);
            
            var f = new Field("Int32", "_Age");
            c.Fields.Add(f);

            var p1 = new Property("String", "Name");
            p1.Modifier.AccessModifier = MethodAccessModifier.Public;
            p1.Get.IsAutomaticProperty = true;
            p1.Set.IsAutomaticProperty = true;
            c.Properties.Add(p1);

            var p2 = new Property("Int32", "Age");
            p2.Get.Body.Add(SourceCodeLanguage.CSharp, "return _Age;");
            p2.Set = null;
            c.Properties.Add(p2);

            var tp = new TypeName("List");
            tp.GenericTypes.Add(new TypeName("Person"));
            var p3 = new Property(tp, "Children");
            p3.Get.IsAutomaticProperty = true;
            p3.Set.IsAutomaticProperty = true;
            p3.Set.Modifier = AccessModifier.Private;
            c.Properties.Add(p3);

            var ct = new Constructor(AccessModifier.Public, "Person");
            ct.Parameters.Add(new MethodParameter("String", "name"));
            ct.Body.Add(SourceCodeLanguage.CSharp, "this.Children = new List<Person>();");
            ct.Body.Add(SourceCodeLanguage.CSharp, "this.Name = name;");
            c.Constructors.Add(ct);

            var m1 = new Method(MethodAccessModifier.Public, "ShowName");
            m1.Body.Add(SourceCodeLanguage.CSharp, "Console.WriteLine(this.Name);");
            c.Methods.Add(m1);

            var m2 = new Method(MethodAccessModifier.Public, "AddAge");
            m2.Parameters.Add(new MethodParameter("Int32", "value"));
            m2.Body.Add(SourceCodeLanguage.CSharp, "_Age += value;");
            c.Methods.Add(m2);

            var sw = new StringWriter();
            var cs = new CSharpSourceCodeGenerator(sw);
            cs.Write(sourceCode);
            Console.WriteLine(sw.ToString());

            Console.ReadLine();
        }
    }
}
